<!-- 密码 -->
<template>
	<view class="pt20">
		<mg-cell @tab="" last="1" isr='1' btt='账户名' bttc="c3 f30" :ft="account.userName" ac="cd" />
		<mg-cell @tab="toChangePassword" isr='1' btt='账户密码' bttc="c3 f30" :ft="account.passWord" :arrow="0" ac="cd"
			cname="mt20" />
		<mg-cell @tab="" isr='1' btt='绑定手机号' bttc="c3 f30" :ft="account.phone||'暂未绑定'" :arrow="0" ac="cd" />
		<mg-cell @tab="" isr='1' btt='最近登陆' bttc="c3 f30" :ft="pt.model+' '+pt.system" :arrow="0" ac="cd" />
		<mg-load v-if="showloading"></mg-load>
		<view class="p3">
			<my-button @confirm="tcdl">退出登录</my-button>
			<!-- <my-button margin-top="40" background="#ddd" v-if="isDev" @confirm="qchc">清除缓存</my-button> -->
		</view>
	</view>


</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations
	} from 'vuex'
	export default {
		name: 'order-index',
		components: {},
		data() {
			return {
				showloading: true,
				mdxx: {},
				pt: {}
			}
		},
		computed: mapState(['account']),
		onLoad(options) {
			this.util.setNT('我的账户')
			this.getsjData()
			this.pt = this.util.getSb()
		},
		computed: {},
		methods: {
			...mapMutations(['delAccount', 'removeAccount']),
			async getsjData() {
				let res = await this.util.request({
					'url': this.api.ymmdxx,
					method: 'POST',
				})
				this.mdxx = res.data
				this.showloading = false
			},
			onClick() {
				this.$emit('click')
			},
			// 跳转修改密码页面
			toChangePassword() {
				uni.navigateTo({
					// url:'../my/other/change-password'
					url: '/yb_shd/my/other/change-password'
				})
			},
			// 退出登录
			async tcdl() {
				try {
					var account = uni.getStorageSync('account')
					await this.util.modal(`确认退出登录吗？`);
					console.log('registrationID:', account.registrationID)
					// 解除极光绑定
					await this.util.request({
						'url': this.api.loginOut,
						method: 'POST',
						data: {
							registrationID: account.registrationID
						}
					})
					this.delAccount();
					var loginUrl = '/yb_shd/my/login'
					this.go({
						t: 3,
						url: loginUrl
					});
				} catch (e) {
					console.error('退出登录失败:', e);
				}
			},
			// 清楚缓存逻辑
			qchc() {
				uni.removeStorageSync('account');
				this.removeAccount({});
				setTimeout(() => {
					var loginUrl = '/yb_shd/my/login'
					this.go({
						t: 3,
						url: loginUrl
					});
				}, 1000);
			}
		},
	}
</script>
<style scoped lang="scss">

</style>